package com.zzxy.mybatis.dao.Impl;

import com.zzxy.mybatis.dao.IUserDao;
import com.zzxy.mybatis.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.support.SqlSessionDaoSupport;

public class UserDaoImpl extends SqlSessionDaoSupport implements IUserDao {

    SqlSession ss;

    public UserDaoImpl(){

    }

    public UserDaoImpl(SqlSession sqlSession){
        this.ss=sqlSession;
    }
    @Override
    public void save(User user) {

        ss.insert("insertUser",user);
        ss.commit();
        ss.close();

    }

    @Override
    public User findUserById(int id) {
        User user=ss.selectOne("findUserById",id);
        ss.close();
        return user;
    }

    @Override
    public User findUserById2(int id) {
        return this.getSqlSession().selectOne("test.findUserById2",id);
    }
}
